/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package presentacion.models;

import business.LaboratorioBO;
import dominio.Laboratorio;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author KOFMASTER
 */
public class ModelLaboratorio extends AbstractTableModel {
    String [] headers = {"Número", "Nombre", "Capacidad", "Disponible", "Descripcion" };
    Class [] classes =
        {   Integer.class, String.class, Integer.class,
            Boolean.class, String.class     };
    private List<Laboratorio> dataList = new ArrayList<Laboratorio>();

    public ModelLaboratorio() {
        super();
        LaboratorioBO bo = new LaboratorioBO();
        dataList = bo.findAll();
    }
    
    public int getRowCount() {
        return getDataList().size();
    }
    
    public int getColumnCount() {
        return headers.length;
    }
   
    public Object getValueAt(int row, int col) {
        if(getDataList()==null || getDataList().size()==0)
          return new Object();
        return getDataList().get(row).getValue(col);
    }

    @Override
    public String getColumnName(int col) {
        return headers[col];
    }

    @Override
    public Class<?> getColumnClass(int col) {
        return classes[col];
    }

   /* @Override
    public boolean isCellEditable(int row, int col) {
        return true;
    }*/

    @Override
    public void setValueAt(Object value, int row, int col) {
        getDataList().get(row).setValue(value, col);
        fireTableCellUpdated(row, col);
    }


    public Laboratorio getRow(int row) {
        if(dataList == null || dataList.size()-1< row)
            return null;
        return dataList.get(row);
    }


    /**
     * @return the dataList
     */
    public List<Laboratorio> getDataList() {
        return dataList;
    }

    /**
     * @param dataList the dataList to set
     */
    public void setDataList(List<Laboratorio> dataList) {
        this.dataList = dataList;
    }

}
